package com.cmrx.model.controller;

import com.cmrx.model.entity.SysDict;
import com.cmrx.model.service.SysdictService;
import com.cmrx.model.util.ResultVoUtil;
import com.cmrx.model.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("sysdict")
@Slf4j
@Api(value = "/sysdict",description = "字典表相关接口类")
public class SysdictController {

	@Autowired
	private SysdictService sysdictService;
	
    @RequestMapping(value = "/select/casetype",method = RequestMethod.POST)
    @ApiOperation(value = "案件类别接口")
    public ResultVo selectInvestigation() {
		return ResultVoUtil.success(sysdictService.selectCaseType());
    }

    @RequestMapping(value = "/select/six/casetype",method = RequestMethod.POST)
    @ApiOperation(value = "六类案件类别接口")
    public ResultVo selectSixInvestigation() {
    	return ResultVoUtil.success(sysdictService.selectSixCaseType());
    }
    
    @RequestMapping(value = "/select/gxsdm",method = RequestMethod.POST)
    @ApiOperation(value = "区划类别接口")
    public ResultVo selectgxsdm() {
		return ResultVoUtil.success(sysdictService.selectgxsdm());
    }

    @RequestMapping(value = "/select/analysis",method = RequestMethod.POST)
    @ApiOperation(value = "分析意见字典接口")
    @ApiImplicitParam(name = "map",value = "{\"rootKey\":\"\"}")
    public ResultVo selectSysdict(@RequestBody Map<String,String> map) {
        String rootKey = map.get("rootKey");
        if(!StringUtils.isEmpty(rootKey)) {
            return ResultVoUtil.success(sysdictService.selectSysdict(rootKey));
        }
		return ResultVoUtil.message("rootKey为空");
    }
    @RequestMapping(value = "/select/one/casetype",method = RequestMethod.POST)
    @ApiOperation(value = "一级一级查询字典接口")
    @ApiImplicitParam(name = "map",value = "{\"rootKey\":\"\",\"parentKey\":\"\"}")
    public ResultVo selectDictByParent(@RequestBody Map<String,String> map) {
//        String rootKey = "AJLBDM";
        String rootKey = map.get("rootKey");
        String parentKey = map.get("parentKey");
        if(StringUtils.isEmpty(parentKey)){
            parentKey = rootKey;
        }
        List<Map<String,Object>> list = sysdictService.selectOneCaseType(rootKey,parentKey);
        if(list.isEmpty()){
            return ResultVoUtil.message("没有下一级");
        }
        for (Map<String, Object> map1 : list) {
            map1.put("type", false);
        }
        return ResultVoUtil.success(list);
    }


    /*手动清空接口*/
    @RequestMapping(value = "/remove/content",method = RequestMethod.POST)
    @ApiOperation(value = "手动清空缓存接口")
    @CacheEvict(value="content",allEntries=true)
    public ResultVo saveUsers() {
        return  ResultVoUtil.message("执行完毕");
    }



    /*获取物证类型*/
    @ApiOperation(value="获取物证类型", notes="根据url的typeId来指定获取物证类型")
    @ApiImplicitParam(name = "typeId", value = "物证id类型", required = true, dataType = "String")
    @RequestMapping(value = "/evidence/{typeId}", method = RequestMethod.GET)
    public ResultVo getEvidenceType(@PathVariable String typeId){
        List<Map<String, Object>> list = new ArrayList<>();
        if("1".equals(typeId)){
            list = sysdictService.selectEvidenceType("SWWZLBDM");
        }else if("2".equals(typeId)){
            list = sysdictService.selectEvidenceType("STWZLBDM");
        }else if("3".equals(typeId)){
            list = sysdictService.selectEvidenceType("ZJHJLXDM");
        }else if("4".equals(typeId)){
            list = sysdictService.selectEvidenceType("ZJTQFFDM");
        }
        return ResultVoUtil.success(list);
    }
}
